package admin

import (
    "net/http"
    "html/template"

    "github.com/gin-gonic/gin"

     "golang-admin/app/models"
    . "golang-admin/app/helpers"
)

// List
func AdminIndex(c *gin.Context) {
    Initialize(c)

    if c.GetHeader("X-Requested-With") == "XMLHttpRequest" {
        // 处理 AJAX 请求逻辑
        sql := "SELECT * FROM admins"
        datas, _ := models.SelectAdmins(sql)

        c.JSON(http.StatusOK, gin.H {
            "code": http.StatusOK,
            "status": 1,
            "data": datas,
            "msg": "success",
        })
    } else {
        dadas := map[string]interface{} {
            "model" : "admin",
            "adminInfo" : adminInfo,
            "sidebar" : template.HTML(sidebar),
        }

        GenerateHTML(c.Writer, "admin/layouts/app", dadas, "admin/layouts/app", "admin/partials/header", "admin/partials/sidebar", "admin/admin/list")
    }
}

func AdminProfile(c *gin.Context) {
    Initialize(c)
}

func AdminResetPassword(c *gin.Context) {
    Initialize(c)
}

func AdminAdd(c *gin.Context) {
    Initialize(c)
}

func AdminEdit(c *gin.Context) {
    Initialize(c)
}

func AdminSavePost(c *gin.Context) {
    Initialize(c)

    if c.Request.Method == "POST" {

    }
}

func AdminDelete(c *gin.Context) {
    //id := c.Query("id")
    Initialize(c)
}

func AdminCheckLoginName(c *gin.Context) {
    Initialize(c)
}
